package net.coding.api.test.helper;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.net.URL;

import static net.coding.api.test.TestClient.CONFIG;

/**
 * Created with IntelliJ IDEA.
 * User: chenfeilong
 * Date: 2018/2/1
 * Time: 14:05
 * Description:
 */
public interface BaseNginxProxyHelper {

    default String getMainSiteUrl() {
        return CONFIG.getProperty("gitHostWithProtocol");
    }

    default String getAdminSiteUrl() {
        return CONFIG.getProperty("adminURI");
    }

    default String getMainSiteTitle() {
        return CONFIG.getProperty("mainSiteTitle");
    }


    default String getAdminSiteTitle() {
        return CONFIG.getProperty("adminSiteTitle");
    }

    default String getTitle(String url) throws IOException {
        //连接超时也算作测试失败
        Document doc = Jsoup.parse(new URL(url), 5 * 1000);
        doc.outputSettings().prettyPrint(false);
        return doc.select("title").html();
    }
}
